/**
 * 
 */
package cz.geoserver.KMLpublisher.db.model;

/**
 * Class for representing name of table from SQL query
 * @author mkepka
 *
 */
public class TableName {

    private String tableName;
    private String alias;
    private boolean hasAlias;

    /**
     * Constructor creates instance of table only with name
     * @param tabName Name of table from SQL command
     */
    public TableName(String tabName){
        this.tableName=tabName;
        this.alias="";
        this.hasAlias=false;
    }

    /**
     * Constructor creates instance of table with name and alias
     * @param tabName Name of table from SQL command
     * @param alias Alias of table from SQL command
     */
    public TableName(String tabName, String alias){
        this.tableName = tabName;
        this.alias=alias;
        this.hasAlias = true;
    }

    /**
     * Methods returns name of table
     * @return the tableName from SQL command
     */
    public String getTableName() {
        return tableName;
    }

    /**
     * Method returns alias of table
     * @return the alias of table from SQL command
     */
    public String getAlias() {
        return alias;
    }

    /**
     * Method returns boolean whether table has alias 
     * @return the hasAlias is true if table has alias, false if not
     */
    public boolean hasAlias() {
        return hasAlias;
    }

    /**
     * Method returns String with table name and alias if it has it 
     * @return name of table or name of table and used alias
     */
    public String toString(){
        if(hasAlias){
            return tableName+" "+alias;
        }
        else{
            return tableName;
        }
    }
}